using UnityEngine;
using System.Collections;

public class Pause : MonoBehaviour {
	private int buttonWidth = 200;
	private int buttonHeight = 25;
	private int groupWidth = 200;
	private int groupHeight = 170;
	public Rect groupPosition = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 80, 310, 170);
	bool paused = false;
	
	void Start () 
	{
		Screen.lockCursor = true;
		Time.timeScale = 1;
	}
	void OnGUI () 
	{
		if(paused)
		{
			GUI.BeginGroup(groupPosition);
			GUI.Box(new Rect(0,0, groupPosition.width, groupPosition.height), "Pause Menu");
			GUI.Label(new Rect((groupPosition.width-150)/2, 25, 170, 40), "Are you sure you want to quit?");
			if(GUI.Button(new Rect(0, 60,buttonWidth,buttonHeight), "Yes"))
			{
				Application.LoadLevel(0);
			}
			if(GUI.Button(new Rect(0, 100,buttonWidth,buttonHeight), "No"))
			{
				Application.LoadLevel(1);
			}
			GUI.EndGroup();
		}
	}
	void Update ()
	{
		if(Input.GetKeyUp(KeyCode.Escape))
			paused = togglePause();
	}
	bool togglePause()
	{
		if(Time.timeScale == 0)
		{
			Screen.lockCursor = true;
			Time.timeScale = 1;
			return(false);
		}
		else
		{
			Screen.lockCursor = false;
			Time.timeScale = 0;
			return(true);
		}
	}
}
